package com.sandking.db.bean;

import com.sandking.tools.SK_Map;
import java.util.ArrayList;
import com.sandking.db.cache.LtCache;
import java.util.Map;
import java.util.List;
import com.sandking.db.cache.LtlxCache;
import java.util.HashMap;

/**
 * 聊天类型
 */
public class Ltlx {
	/**
	 * 需要更新字段集
	 */
	private Map<String, Object> updateColumns;

	/** id */
	private int id;
	
	/** 名称 */
	private String mc;
	
	
	public Ltlx() {
		super();
	}
	
	public Ltlx(int id, String mc) {
		super();
		this.id = id;
		this.mc = mc;
	}
	
	public Map<String, Object> getUpdateColumns() {
		if(updateColumns == null)
			updateColumns = new HashMap<String, Object>();
		return updateColumns;
	}
	
	public int getId() {
		return id;
	}
	
	public void setId(int id) {
		this.id = id;
		addUpdateColumn("id",id);
	}
	
	public void changeIdWith(int id){
		this.id += id;
		setId(this.id);
	}
	
	public void changeIdWithMin(int id,int min){
		this.id += id;
		this.id = this.id < min ? min : this.id;
		setId(this.id);
	}
	
	public void changeIdWithMax(int id,int max){
		this.id += id;
		this.id = this.id > max ? max : this.id;
		setId(this.id);
	}
	
	public void changeIdWithMaxMin(int id,int max,int min){
		this.id += id;
		this.id = this.id < min ? min : this.id;
		this.id = this.id > max ? max : this.id;
		setId(this.id);
	}	
	public String getMc() {
		return mc;
	}
	
	public void setMc(String mc) {
		this.mc = mc;
		addUpdateColumn("名称",mc);
	}
	
	
	//id
	public List<Lt> getLtsFkLtlx_id(){
		return LtCache.getByLtlx_id(id);
	}
	
	public void addUpdateColumn(String key, Object val) {
		Map<String, Object> map = getUpdateColumns();
		if (map == null)
			return;
		map.put(key, val);
	}
	
	public void clearUpdateColumn() {
		Map<String, Object> map = getUpdateColumns();
		if (map == null)
			return;
		map.clear();
	}
	
	public Map<String, Object> toMap(){
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("id", id);
        result.put("mc", mc);
        return result;
    }
    
    public String toString(){
        return toMap().toString();
    }
    
    /**
     * 根据list创建对象
     */
    public static List<Ltlx> createForList(List<Map<String, Object>> list){
    	List<Ltlx> ltlxs = new ArrayList<Ltlx>();
		for (Map<String, Object> map : list) {
			ltlxs.add(createForMap(map));
		}
		return ltlxs;
    }
    
    /**
     * 根据map创建对象
     */
    public static Ltlx createForMap(Map<String, Object> map){
    	Ltlx obj = new Ltlx();
	    obj.id = SK_Map.getInt("id", map);
	    obj.mc = SK_Map.getString("名称", map);
        return obj;
    }
    /** 延迟插入数据库 */
    public Ltlx insert(){
    	return LtlxCache.insert(this);
    }
    /** 延迟更新数据库 */
    public Ltlx update(){
    	return LtlxCache.update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return LtlxCache.delete(this);
    }
    /** 即时插入数据库 */
    public Ltlx insertAndFlush(){
    	return LtlxCache.insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public Ltlx updateAndFlush(){
    	return LtlxCache.updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return LtlxCache.deleteAndFlush(this);
    }
}